// 导入 axios
import service from '@/utils/request'

// GET /admin/product/attrInfoList/{category1Id}/{category2Id}/{category3Id}

// DELETE /admin/product/deleteAttr/{attrId}

// /admin/product/saveAttrInfo  新增

// /admin/product/saveAttrInfo  修改
// 定义 attrValueList 类型规范
export interface attrValueListModel {
  attrId?: number
  id?: number
  valueName: string
  isDone: boolean
}
// 定义data 数据类型规范
export interface attrDataModel {
  id?: number
  attrName: string
  attrValueList: attrValueListModel[]
  categoryId: number | undefined
  categoryLevel: number
  attrIdValId?: string | undefined
}
// 定义整体 返回值接口类型规范
export interface attrListModel {
  code: number
  data: attrDataModel[]
}

// 定义api
/**
 * @desc 获取展示数据的接口api
 * @param category1Id 一级分类下拉数据id
 * @param category2Id 二级分类下拉数据id
 * @param category3Id 三级分类下拉数据id
 * @returns Promise
 */
export const attrInfoList = (category1Id: number, category2Id: number, category3Id: number) => {
  return service.get<any, attrListModel>(`/admin/product/attrInfoList/${category1Id}/${category2Id}/${category3Id}`)
}

// 定义新增数据的 接口类型规范

export interface PostOrdeleteAttrInfoModel {
  code: number
  data: null
}
/**
 * @desc 新增数据
 * @param attrInfoForm 表单数据
 * @returns Promise
 */
export const saveAttrInfo = (attrInfoForm: attrDataModel) => {
  return service.post<any, PostOrdeleteAttrInfoModel>('/admin/product/saveAttrInfo', attrInfoForm)
}

// 删除数据的api
/**
 * @desc 删除数据api
 * @param attrId 需要删除当前数据的id
 * @returns Promise
 */
export const deleteAttr = (attrId: number) => {
  return service.delete<any, PostOrdeleteAttrInfoModel>(`/admin/product/deleteAttr/${attrId}`)
}
